package com.qf.rabbitmq.work;

import com.qf.rabbitmq.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class Sender {
    //    声明了一个 队列名
    private static final String QUEUENAME="bk2102";

    public static void main(String[] args) throws Exception {
//        获取连接
        Connection connection = ConnectionUtil.getConnection();
//        通过连接获取通道
        Channel channel = connection.createChannel();
//        通过通道声明队列
        channel.queueDeclare(QUEUENAME, false, false, false, null);

        for (int i = 0; i < 100; i++) {
            //        发送            2 队列名字   3 附加的参数  4 要发送的内容
            channel.basicPublish("", QUEUENAME, null, ("你真帅"+i).getBytes(StandardCharsets.UTF_8));

        }

        //        关闭
        channel.close();
        connection.close();

    }
}
